# coding=utf-8
##
## Author: jmdvirus@aliyun.com
##
## Create: Thu Jun 17 20:08:21 2021
##

import keras
import numpy as np
import tensorflow as tf
from keras.models import Sequential
from keras.datasets import mnist
from keras.preprocessing import image
from PIL import Image

img_size = 28*28
num_classes = 10

model = keras.models.load_model("out/simple.rkbn")

(x_train, y_train), (x_test, y_test) = mnist.load_data()
y_test = tf.keras.utils.to_categorical(y_test, num_classes)

x_simg = x_test[0:1]
print("x_simg shape {}".format(x_simg.shape))
x_simg = Image.fromarray(np.reshape(x_simg, (28,28)))
x_simg.save("/opt/data/testdata/ai/ai1.jpg")

x_test = x_test.reshape(x_test.shape[0], img_size)
x_test = x_test.astype('float32')

#score=model.evaluate(x_test, y_test, verbose=0)
#print("Test accuracy:{}, Test loss:{},{}".format(score[1], score[0], score))

x_img = x_test[0:1]
prediction = model.predict(x_img)

print(prediction)


